package com.sigmatrix.h5.web.controller.utils;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sigmatrix.h5.entity.v2.DisAcctRole;
import com.sigmatrix.h5.entity.v2.DisPermission;
import com.sigmatrix.h5.entity.v2.DisRole;
import com.sigmatrix.h5.entity.v2.DisRolePermission;
import com.sigmatrix.h5.service.db.DisAcctRoleDBService;
import com.sigmatrix.h5.service.db.DisPermissionDBService;
import com.sigmatrix.h5.service.db.DisRolePermissionDBService;
import com.sigmatrix.h5.service.db.DisRoleDBService;
import com.sigmatrix.h5.web.BaseController;

/**
 * 权限相关。测试mybatic常用操作
 * 
 * @author wei.wang
 *
 */
@RestController
@RequestMapping("/util/test")
public class TestPermissionController extends BaseController {

	@Autowired
	private DisPermissionDBService disPermissionService;
	
	@Autowired
	private DisAcctRoleDBService disAcctRoleService;
	
	@Autowired
	private DisRoleDBService disRoleService;
	
	@Autowired
	private DisRolePermissionDBService disRolePermissionService;
	
	@Autowired
	private DisRoleDBService DisRoleServiceImplV2;

	@GetMapping("/acctRole/selectList/acct/{id}")
	public List<DisAcctRole> selectByIdInAcctRole(@PathVariable Integer id) {
		DisAcctRole entity = new DisAcctRole();
		entity.setAcctId(id);
		return disAcctRoleService.selectList(new EntityWrapper<DisAcctRole>(entity));
	}
	
	@GetMapping("/role/select/id/{id}")
	public DisRole selectByIdInRole(@PathVariable Integer id) {
		return disRoleService.selectById(id,null);
	}
	
	@GetMapping("/permission/select/id/{id}")
	public DisPermission selectByIdInPermission(@PathVariable Integer id) {
		return disPermissionService.selectById(id,null);
	}
	
	@GetMapping("/rolePermission/selectList/role/{id}")
	public List<DisRolePermission> selectByIdInrolePermission(@PathVariable Integer id) {
		DisRolePermission entity = new DisRolePermission();
		entity.setRoleId(id);
		return disRolePermissionService.selectList(new EntityWrapper<DisRolePermission>(entity));
	}
	@GetMapping("/get")
	public DisRole get() {
		return DisRoleServiceImplV2.findAdmin();
	}
	
}
